package test.xiaomi;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

/**
 * @description: 72 + 67
 * @author: w_jingbo
 * @date: 2023/9/23
 * @Copyright: 博客：http://coisini.wang
 */
public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = Integer.parseInt(in.nextLine());
        String[] split = in.nextLine().split(",");
        List<int[]> list = new ArrayList<>();
        for (int i = 0; i < split.length; i++) {
            String s1 = split[i] ;
            String[] split1 = s1.split(":");
            int[] arr = new int[2] ;
            arr[0] = Integer.parseInt(split1[0]) ;
            arr[1] = Integer.parseInt(split1[1]) ;
            if(arr[0] < arr[1] || Math.abs(arr[0] - arr[1]) > 1){
                System.out.println(0) ;
                return;
            }
            list.add(arr);
        }
        List<String> isHave = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            int[] arr = list.get(i) ;
            if(arr[1] == 0){
                isHave.add(String.valueOf(arr[0]));
            }else {
                if(!isHave.contains(String.valueOf(arr[1]))){
                    System.out.println(0);
                    return;
                }
                isHave.add(String.valueOf(arr[0]));
                isHave.remove(String.valueOf(arr[1]));

            }

        }
        for (String s : isHave) {
            int a = Integer.parseInt(s);
            if (a != n-1){
                System.out.println(0);
            }
        }
        System.out.println(1);
        /*for (String s : isHave) {
            int a = Integer.parseInt(s);
            if(a == n - 1){
                System.out.println(1);
                return;
            }
        }
        System.out.println(0);*/



    }
}


/*

Scanner in = new Scanner(System.in);
        String[] split = in.nextLine().split(",");
        int n = Integer.parseInt(split[0]);
        int rad = Integer.parseInt(split[1]);
        List<int[]> list = new ArrayList<>();
        int max = 0 ;
        int index = 0 ;
        for (int i = 0; i < n; i++) {
            int[] arr = new int[3] ;

            String[] strs = in.nextLine().split(",") ;
            arr[0] = Integer.parseInt(strs[0]) ;
            arr[1] = Integer.parseInt(strs[1]) ;
            arr[2] = Integer.parseInt(strs[2]) ;
            list.add(arr);
        }
        for (int i = 0; i < n; i++) {
            int[] arr1 = list.get(i) ;
            int curMax = arr1[2] ;
            for (int j = 0; j < n; j++) {

                if(j == i){
                    continue;
                }
                int[] arr2 = list.get(j);
                int xy2 = Math.abs(arr1[0] - arr2[0]) * Math.abs(arr1[0] - arr2[0]) + Math.abs(arr1[1] - arr2[1]) * Math.abs(arr1[1] - arr2[1]) ;
                int d = (int) Math.sqrt(xy2) ;
                curMax += arr2[2] / (1 + d) ;
            }
            if(curMax > max){
                max = curMax ;
                index = i ;
            }
        }
        int i = list.get(index)[0] ;
        int j = list.get(index)[1] ;
        System.out.println(i + "," + j);

 */
